$(function(){
    $(".activity-left-opts span").click(function (e) {
        e.preventDefault();
        $(this).siblings("span").removeClass("selected");
        $(".activity-project").css("display", "none");
        $(this).addClass("selected");
        var index = $(this).attr('data-value');
        $(".activity-content-" + index).css("display", "block");
        ActivityList.customPage('1', index);
    });
});

// window.onload = function(){
    // setWindow();
// }

// function setWindow(){
//     var height = document.documentElement.clientHeight;
//     var tab = Array.prototype.slice.call(document.getElementById("right-bottom-content").children);
//     document.getElementById("right-bottom-content").style.height = height - 74 - 39 + "px";
//     for(var i = 1; i < 6; i++){
//         tab[i].style.height = height-74-39-48-50 + "px";
//         tab[i].style.overflowY = "auto";
//         tab[i].style.marginBottom = 0;
//         tab[i].style.marginTop = 10+"px";
//     }
// }

/**
 * 我的活动列表
 * @type {{customPage: ActivityList.customPage, callback: ActivityList.callback}}
 */
var ActivityList = {
    customPage: function (pageId, type) {
        baseAjax("/myActivity/getMyActivityList/",{pageId : pageId, type:type},
            function(){
                var result = this;
                var data = result.data;
                var timestamp = new Date().getTime()/1000;
                switch (parseInt(type)){
                    case 0:
                        $('#activity_list_all').html('');
                        if (data != null && data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                if (timestamp > parseInt(data[i].stime) && timestamp < parseInt(data[i].etime)) {
                                    data[i].ing = 1;
                                }
                                var activity_item = template("activity_item", data[i]);
                                $('#activity_list_all').append(activity_item);
                            }
                        } else {
                            $('#activity_list_all').append('<div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                        }
                        break;
                    case 1:
                        $('#activity_list_ing').html('');
                        if (data != null && data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                data[i].ing = 1;
                                var activity_item = template("activity_item", data[i]);
                                $('#activity_list_ing').append(activity_item);
                            }
                        } else {
                            $('#activity_list_ing').append('<div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                        }
                        break;
                    case 2:
                        $('#activity_list_end').html('');
                        if (data != null && data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                var activity_item = template("activity_item", data[i]);
                                $('#activity_list_end').append(activity_item);
                            }
                        } else {
                            $('#activity_list_end').append('<div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                        }
                        break;
                    case 3:
                        $('#activity_list_die').html('');
                        if (data != null && data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                var activity_item = template("activity_item", data[i]);
                                $('#activity_list_die').append(activity_item);
                            }
                        } else {
                            $('#activity_list_die').append('<div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                        }
                        break;
                    case 4:
                        $('#activity_list_draft').html('');
                        if (data != null && data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                var draft_item = template("draft_item", data[i]);
                                $('#activity_list_draft').append(draft_item);
                            }
                        } else {
                            $('#activity_list_draft').append('<div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                        }
                        break;
                    case 5:
                        $('#activity_list_sign_up').html('');
                        if (data != null && data.length > 0) {
                            for (var i = 0; i < data.length; i++) {
                                var activity_item = template("activity_item", data[i]);
                                $('#activity_list_sign_up').append(activity_item);
                            }
                        } else {
                            $('#activity_list_sign_up').append('<div class="no-data-box"><img class="no-data-img" src="/Public/image/www/no-data.png" alt="这是图片" /><p class="no-data-title">这里什么也没有</p></div>');
                        }
                        break;
                }
            },
            function(){
                var result = this;
                layer.msg(result.msg);
            }
        );
    },
    delDraft:function(el,id){
        if(id != ''){
            layer.confirm("确定要删除吗",
                    {
                        area:['265px','auto'],
                        btn: ['确定', '取消'],
                        skin:'lay-delete',
                        title:false,
                        closeBtn:false,
                        content:'确定要删除吗？'
                    },
                    function (index) {
                        myActivityListRequest.delDraft(id, function(res){
                            if(res.code == 1){
                                $(el).closest(".activity-item").remove();
                            }
                            layer.msg(res.msg);
                        });
                    }, function () {
                        return true;
                    }
            );              
        }

    }
};
